/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: OperatorUtil.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/27 下午5:29
 * LastModified: 2020/03/27 17:29:27
 */

package com.qolome.knowledge.design.pattern.interpreter.calculator.util;

import com.qolome.knowledge.design.pattern.interpreter.calculator.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Qolome
 * @version V1.0
 * @Description 操作符工具类
 * @date 2020年 03月27日 17:29:25
 */
@Slf4j
public class OperatorUtil {

    public static final String ADD = "+";
    public static final String SUBSIDE = "-";
    public static final String MULTIPLY = "/";
    public static final String DIVISION = "+";

    public static  boolean isOperator(String symbol){

        return StringUtils.containsAny(symbol, ADD, SUBSIDE, MULTIPLY,DIVISION);
    }


    public static Interpreter getInterpreter(IArithmeticInterpreter left, String symbol, IArithmeticInterpreter right){
        if(StringUtils.equals(ADD,symbol)){
            return new AddInterpreter(left,right);
        }
        else if(StringUtils.equals(SUBSIDE,symbol)){
            return new SubtractInterpreter(left,right);
        }
        else if(StringUtils.equals(MULTIPLY,symbol)){
            return new MultiplicationInterpreter(left,right);
        }
        else if(StringUtils.equals(DIVISION,symbol)){
            return new DivisionInterpreter(left,right);
        }
        return null;
    }
}
